// ========================================
// NRC Comprehensive Vec Test Suite
// ========================================
//
// This file comprehensively tests NRC's Vec functionality
//
// Test Modules:
// - PART A: Basic Operations (creation, access, modification)
// - PART B: Built-in Functions (len, cap, push)
// - PART C: Value Type Semantics (deep copy, independence)
// - PART D: Syntax Extensions (cap: and count: parameters)
// - PART E: Memory Management (automatic cleanup)
// - PART F: Advanced Integration (complex operations)
// - PART G: Push Method Verification (append elements)
// - PART H: Pop Method Verification (delete last element)
// - PART I: Remove Method Verification (delete at index)
// - PART J: Insert Method Verification (insert element)
// - PART K: Reserve Method Verification (pre-allocate capacity)
// - PART L: Contains Method Verification (element checking)
// - PART M: Extend Method Verification (concatenate vectors)
// - PART N: For-In Loop Iteration (value iteration)
//
// Core Features:
// 1. Value Type Semantics - Assignment and vector range are deep copies
// 2. Automatic Memory Management - Stack vectors automatically cleaned
// 3. Complete Method Set - len, cap, push, pop, insert, remove, reserve, contains, extend
// 4. Syntax Extensions - Vec<T>{cap: N}, Vec<T>{value; count: N}
// 5. Vec Range - s[start:end], s[:end], s[start:], s[:] (deep copy)
// 6. For-In Iteration - for var v T in vector {} (value copy)
//
// Design Philosophy:
// - Safety First: Deep copy avoids accidental sharing
// - Simple and Intuitive: Clear value semantics, low mental burden
// - Zero-Cost Abstraction: Stack allocation, compile-time optimization
// - Rust-Style API: Method calls, modern programming habits
//
// Reference Documentation:
// - SLICE_DESIGN.MD - Vec design philosophy and implementation details
// - VECTOR_OPERATIONS_COMPARISON.md - Feature comparison with Rust/Go
//
// ========================================

// ========================================
// Helper Functions for Testing
// ========================================

func test_basic_vector_cleanup() {
    println("=== Test: Basic Stack Vec Cleanup ===")
    var s Vec<int> = Vec<int>{1, 2, 3, 4, 5}
    println("Created vector with 5 elements")
    println("Vec will be auto-cleaned when function exits")
}

func test_multiple_vectors_cleanup() {
    println("=== Test: Multiple Stack Vecs Cleanup ===")
    var s1 Vec<int> = Vec<int>{10, 20, 30}
    var s2 Vec<int> = Vec<int>{40, 50, 60, 70}
    var s3 Vec<int> = Vec<int>{80}
    println("Created 3 vectors - all will be auto-cleaned")
}

func test_early_return_cleanup() {
    println("=== Test: Early Return Cleanup ===")
    var s Vec<int> = Vec<int>{100, 200, 300, 400, 500}
    println("Created vector")
    var condition bool = true
    if condition {
        println("Early return - vector still cleaned!")
        return
    }
    println("Should not reach here")
}

func test_function_scope_cleanup() {
    println("=== Test: Function Scope Cleanup ===")
    var outer Vec<int> = Vec<int>{1, 2}
    println("Created outer vector")
    var inner Vec<int> = Vec<int>{3, 4, 5}
    println("Created inner vector")
    println("Both vectors alive")
}

func test_different_types() {
    println("=== Test: Different Element Types ===")
    var int_vector Vec<int> = Vec<int>{1, 2, 3}
    println("Created int vector")
    var bool_vector Vec<bool> = Vec<bool>{true, false, true}
    println("Created bool vector")
    println("All vectors will be auto-cleaned")
}

func test_empty_vector() {
    println("=== Test: Empty Vec ===")
    var empty Vec<int> = Vec<int>{}
    println("Created empty vector")
    println("Empty vector will be cleaned too")
}

// ========================================
// Main Test Suite
// ========================================

func test_vector_basic_operations() {
    println("========================================")
    println("NRC Comprehensive Vec Test Suite")
    println("========================================")
    println("DEBUG: This is a test message to verify file is being read")
    println("")

    // =====================================================
    // PART A: Basic Operations
    // =====================================================
    println("[PART A] Basic Vec Operations")
    println("")

    println("A1. Vec Creation")
    var nums Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    Created: Vec<int>{10, 20, 30, 40, 50}")
    println("    Length:", nums.len(), "Capacity:", nums.cap())
    assert(nums.len() == 5, "nums length should be 5")
    assert(nums.cap() == 5, "nums capacity should be 5")
    
    var floats Vec<float32> = Vec<float32>{1.1, 2.2, 3.3}
    println("    Created: Vec<float32>{1.1, 2.2, 3.3}")
    println("    Length:", floats.len(), "Capacity:", floats.cap())
    assert(floats.len() == 3, "floats length should be 3")
    assert(floats.cap() == 3, "floats capacity should be 3")
    
    var empty Vec<int> = Vec<int>{}
    println("    Empty vector - Length:", empty.len(), "Capacity:", empty.cap())
    assert(empty.len() == 0, "empty vector length should be 0")
    assert(empty.cap() == 0, "empty vector capacity should be 0")
    println("    [PASS] Vec creation assertions")
    println("")

    println("A2. Vec Element Access")
    var nums2 Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    nums2[0] =", nums2[0])
    println("    nums2[2] =", nums2[2])
    println("    nums2[4] =", nums2[4])
    assert(nums2[0] == 10, "nums2[0] should be 10")
    assert(nums2[2] == 30, "nums2[2] should be 30")
    assert(nums2[4] == 50, "nums2[4] should be 50")
    println("    [PASS] Element access assertions")
    println("")

    println("A3. Vec Element Modification")
    var nums3 Vec<int> = Vec<int>{10, 20, 30}
    println("    Before: nums3[1] =", nums3[1])
    assert(nums3[1] == 20, "nums3[1] should be 20 before modification")
    nums3[1] = 200
    println("    After:  nums3[1] =", nums3[1])
    assert(nums3[1] == 200, "nums3[1] should be 200 after modification")
    println("    [PASS] Element modification assertions")
    println("")

    println("[PASSED] Basic operations")
    println("")

}

func test_vector_builtin_functions() {
    println("[PART B] Built-in Functions (len, cap, push)")
    println("")

    println("B1. .len() and .cap() functions")
    var vec1 Vec<int> = Vec<int>{1, 2, 3, 4, 5}
    println("    Vec<int>{1, 2, 3, 4, 5}")
    println("    vec1.len() =", vec1.len())
    println("    vec1.cap() =", vec1.cap())
    assert(vec1.len() == 5, "vec1 length should be 5")
    assert(vec1.cap() == 5, "vec1 capacity should be 5")
    println("    [PASS] len/cap function assertions")
    println("")

    println("B2. Vec push - Rust-style syntax")
    var nums5 Vec<int> = Vec<int>{10, 20, 30}
    println("    Initial: Length:", nums5.len())
    assert(nums5.len() == 3, "Initial length should be 3")
    nums5.push(40)
    println("    After nums5.push(40)")
    println("    Length:", nums5.len(), "Capacity:", nums5.cap())
    println("    nums5[3] =", nums5[3])
    assert(nums5.len() == 4, "Length should be 4 after push")
    assert(nums5[3] == 40, "nums5[3] should be 40")
    assert(nums5.cap() >= 4, "Capacity should be at least 4")
    println("    [PASS] Push assertions")
    println("")

    println("B3. Vec push - Method syntax")
    var nums6 Vec<int> = Vec<int>{1, 2, 3}
    println("    Initial: Length:", nums6.len())
    assert(nums6.len() == 3, "Initial length should be 3")
    nums6.push(4)
    println("    After nums6.push(4)")
    println("    Length:", nums6.len(), "Capacity:", nums6.cap())
    println("    nums6[3] =", nums6[3])
    assert(nums6.len() == 4, "Length should be 4 after first push")
    assert(nums6[3] == 4, "nums6[3] should be 4")

    nums6.push(5)
    nums6.push(6)
    println("    After more pushes: Length:", nums6.len())
    println(
        "    Elements:",
        nums6[0],
        nums6[1],
        nums6[2],
        nums6[3],
        nums6[4],
        nums6[5],
    )
    assert(nums6.len() == 6, "Length should be 6 after all pushes")
    assert(nums6[4] == 5, "nums6[4] should be 5")
    assert(nums6[5] == 6, "nums6[5] should be 6")
    println("    [PASS] Method push assertions")
    println("")

    println("B4. Dynamic capacity growth")
    var growth Vec<int> = Vec<int>{1}
    println("    Initial capacity:", growth.cap())
    assert(growth.cap() == 1, "Initial capacity should be 1")
    growth.push(2)
    println("    After 1 push: Capacity:", growth.cap())
    assert(growth.cap() >= 2, "Capacity should be at least 2 after first push")
    growth.push(3)
    println("    After 2 pushes: Capacity:", growth.cap())
    assert(growth.cap() >= 3, "Capacity should be at least 3 after second push")
    println("    [PASS] Dynamic capacity growth assertions")
    println("")

    println("[PASSED] Built-in functions")
    println("")
}

func test_vector_value_semantics() {
    // =====================================================
    // PART C: Value Type Semantics (Deep Copy)
    // =====================================================
    println("[PART C] Value Type Semantics - Deep Copy")
    println("")

    println("C1. Assignment independence")
    var original Vec<int> = Vec<int>{1, 2, 3, 4, 5}
    println("    original: [1, 2, 3, 4, 5]")
    var copy Vec<int> = original
    println("    copy = original")
    assert(original[2] == 3, "original[2] should be 3 before modification")
    assert(copy[2] == 3, "copy[2] should be 3 before modification")
    println("    Modifying copy[2] = 999")
    copy[2] = 999
    println("    original[2] =", original[2], "(unchanged)")
    println("    copy[2] =", copy[2], "(modified)")
    assert(original[2] == 3, "original[2] should remain 3 after copy modification")
    assert(copy[2] == 999, "copy[2] should be 999 after modification")
    println("    [PASS] Assignment independence assertions")
    println("")

    println("C2. Multiple assignments")
    var a Vec<int> = Vec<int>{10, 20, 30}
    var b Vec<int> = a
    var c Vec<int> = b
    println("    a = Vec<int>{10, 20, 30}")
    println("    b = a")
    println("    c = b")
    assert(a[0] == 10, "a[0] should be 10")
    assert(a[1] == 20, "a[1] should be 20")
    assert(a[2] == 30, "a[2] should be 30")
    assert(b[0] == 10, "b[0] should be 10")
    assert(b[1] == 20, "b[1] should be 20")
    assert(b[2] == 30, "b[2] should be 30")
    assert(c[0] == 10, "c[0] should be 10")
    assert(c[1] == 20, "c[1] should be 20")
    assert(c[2] == 30, "c[2] should be 30")
    println("    Modifying each vector:")
    a[0] = 11
    b[1] = 22
    c[2] = 33
    println("    a[0] =", a[0], "a[1] =", a[1], "a[2] =", a[2])
    println("    b[0] =", b[0], "b[1] =", b[1], "b[2] =", b[2])
    println("    c[0] =", c[0], "c[1] =", c[1], "c[2] =", c[2])
    assert(a[0] == 11, "a[0] should be 11")
    assert(a[1] == 20, "a[1] should be 20")
    assert(a[2] == 30, "a[2] should be 30")
    assert(b[0] == 10, "b[0] should be 10")
    assert(b[1] == 22, "b[1] should be 22")
    assert(b[2] == 30, "b[2] should be 30")
    assert(c[0] == 10, "c[0] should be 10")
    assert(c[1] == 20, "c[1] should be 20")
    assert(c[2] == 33, "c[2] should be 33")
    println("    [PASS] Multiple assignment independence assertions")
    println("")

    println("C3. Push independence")
    var vector1 Vec<int> = Vec<int>{100, 200}
    println("    vector1: [100, 200], len:", vector1.len())
    var vector2 Vec<int> = vector1
    println("    vector2 = vector1")
    assert(vector1.len() == 2, "vector1 initial length should be 2")
    assert(vector2.len() == 2, "vector2 initial length should be 2")
    vector1.push(300)
    vector1.push(400)
    println("    After vector1.push(300, 400):")
    println("    vector1 len:", vector1.len())
    println("    vector2 len:", vector2.len(), "(unchanged)")
    assert(vector1.len() == 4, "vector1 length should be 4 after pushes")
    assert(vector2.len() == 2, "vector2 length should remain 2")
    assert(vector1[2] == 300, "vector1[2] should be 300")
    assert(vector1[3] == 400, "vector1[3] should be 400")
    println("    [PASS] Push independence assertions")
    println("")

    println("C4. Value preservation")
    var data_nums Vec<int> = Vec<int>{5, 10, 15, 20, 25}
    var backup Vec<int> = data_nums
    println("    Created backup copy")
    assert(data_nums[0] == 5, "data_nums[0] should be 5 initially")
    assert(data_nums[4] == 25, "data_nums[4] should be 25 initially")
    assert(backup[0] == 5, "backup[0] should be 5 initially")
    assert(backup[4] == 25, "backup[4] should be 25 initially")
    data_nums[0] = 999
    data_nums[4] = 888
    println("    After modifying data_nums:")
    println("    data_nums:   [999, 10, 15, 20, 888]")
    println("    backup: [", backup[0], backup[1], backup[2], backup[3], backup[4], "]")
    assert(data_nums[0] == 999, "data_nums[0] should be 999")
    assert(data_nums[4] == 888, "data_nums[4] should be 888")
    assert(backup[0] == 5, "backup[0] should remain 5")
    assert(backup[4] == 25, "backup[4] should remain 25")
    println("    [PASS] Value preservation assertions")
    println("")

    println("[PASSED] Value type semantics")
    println("")
}

func test_vector_syntax_extensions() {
    println("[PART D] Syntax Extensions - cap: and count:")
    println("")

    println("D1. Elements with capacity")
    var extVec1 Vec<int> = Vec<int>{1, 2, 3, 4, 5; cap: 10}
    var l1 int64 = extVec1.len()
    var c1 int64 = extVec1.cap()
    println("    Vec<int>{1, 2, 3, 4, 5; cap: 10}")
    println("    Length:", l1, "Capacity:", c1)
    println("    Elements:", extVec1[0], extVec1[1], extVec1[2], extVec1[3], extVec1[4])
    assert(extVec1.len() == 5, "extVec1 length should be 5")
    assert(extVec1.cap() == 10, "extVec1 capacity should be 10")
    assert(extVec1[0] == 1, "extVec1[0] should be 1")
    assert(extVec1[4] == 5, "extVec1[4] should be 5")
    println("    [PASS] Elements with capacity assertions")
    println("")

    println("D2. Empty vector with capacity")
    var extVec2 Vec<int> = Vec<int>{cap: 100}
    var l2 int64 = extVec2.len()
    var c2 int64 = extVec2.cap()
    println("    Vec<int>{cap: 100}")
    println("    Length:", l2, "Capacity:", c2)
    assert(extVec2.len() == 0, "extVec2 length should be 0")
    assert(extVec2.cap() == 100, "extVec2 capacity should be 100")
    println("    [PASS] Empty vector with capacity assertions")
    println("")

    println("D3. Repeating elements")
    var extVec3 Vec<int> = Vec<int>{42; count: 5}
    var l3 int64 = extVec3.len()
    var c3 int64 = extVec3.cap()
    println("    Vec<int>{42; count: 5}")
    println("    Length:", l3, "Capacity:", c3)
    println("    Elements:", extVec3[0], extVec3[1], extVec3[2], extVec3[3], extVec3[4])
    assert(extVec3.len() == 5, "extVec3 length should be 5")
    assert(extVec3.cap() == 5, "extVec3 capacity should be 5")
    assert(extVec3[0] == 42, "extVec3[0] should be 42")
    assert(extVec3[4] == 42, "extVec3[4] should be 42")
    println("    [PASS] Repeating elements assertions")
    println("")

    println("D4. Repeating elements with capacity")
    var extVec4 Vec<int> = Vec<int>{0; count: 3, cap: 10}
    var l4 int64 = extVec4.len()
    var c4 int64 = extVec4.cap()
    println("    Vec<int>{0; count: 3, cap: 10}")
    println("    Length:", l4, "Capacity:", c4)
    println("    Elements:", extVec4[0], extVec4[1], extVec4[2])
    assert(extVec4.len() == 3, "extVec4 length should be 3")
    assert(extVec4.cap() == 10, "extVec4 capacity should be 10")
    assert(extVec4[0] == 0, "extVec4[0] should be 0")
    assert(extVec4[2] == 0, "extVec4[2] should be 0")
    println("    [PASS] Repeating elements with capacity assertions")
    println("")

    println("D5. String vectors with capacity")
    var extVec5 Vec<String> = Vec<String>{cap: 50}
    var l5 int64 = extVec5.len()
    var c5 int64 = extVec5.cap()
    println("    Vec<String>{cap: 50}")
    println("    Length:", l5, "Capacity:", c5)
    assert(extVec5.len() == 0, "extVec5 length should be 0")
    assert(extVec5.cap() == 50, "extVec5 capacity should be 50")
    println("    [PASS] String vector with capacity assertions")
    println("")

    println("D6. Float vectors with repeating elements and capacity")
    var extVec6 Vec<float32> = Vec<float32>{0.0; count: 100, cap: 200}
    var l6 int64 = extVec6.len()
    var c6 int64 = extVec6.cap()
    println("    Vec<float32>{0.0; count: 100, cap: 200}")
    println("    Length:", l6, "Capacity:", c6)
    println("    First few elements:", extVec6[0], extVec6[1], extVec6[2])
    assert(extVec6.len() == 100, "extVec6 length should be 100")
    assert(extVec6.cap() == 200, "extVec6 capacity should be 200")
    assert(extVec6[0] == 0.0, "extVec6[0] should be 0.0")
    assert(extVec6[99] == 0.0, "extVec6[99] should be 0.0")
    println("    [PASS] Float vector with repeat and capacity assertions")
    println("")

    println("D7. Push to vector with pre-allocated capacity")
    var extVec7 Vec<int> = Vec<int>{1, 2, 3; cap: 20}
    var l7a int64 = extVec7.len()
    var c7a int64 = extVec7.cap()
    println("    Vec<int>{1, 2, 3; cap: 20}")
    println("    Before push - Length:", l7a, "Capacity:", c7a)
    assert(extVec7.len() == 3, "Initial length should be 3")
    assert(extVec7.cap() == 20, "Initial capacity should be 20")
    extVec7.push(4)
    extVec7.push(5)
    var l7b int64 = extVec7.len()
    var c7b int64 = extVec7.cap()
    println("    After push - Length:", l7b, "Capacity:", c7b)
    println("    Elements:", extVec7[0], extVec7[1], extVec7[2], extVec7[3], extVec7[4])
    assert(extVec7.len() == 5, "Length should be 5 after push")
    assert(extVec7.cap() == 20, "Capacity should remain 20")
    assert(extVec7[3] == 4, "extVec7[3] should be 4")
    assert(extVec7[4] == 5, "extVec7[4] should be 5")
    println("    [PASS] Push to pre-allocated vector assertions")
    println("")

    println("[PASSED] Syntax extensions")
    println("")
}

func test_vector_memory_management_section() {
    println("[PART E] Memory Management - Auto Cleanup")
    println("")

    test_basic_vector_cleanup()
    println("")

    test_multiple_vectors_cleanup()
    println("")

    test_early_return_cleanup()
    println("")

    test_function_scope_cleanup()
    println("")

    test_different_types()
    println("")

    test_empty_vector()
    println("")

    println("[PASSED] Memory management")
    println("")
}

func test_vector_advanced_integration() {
    println("[PART F] Advanced Integration")
    println("")

    println("F1. Comprehensive integration")
    println("    DEBUG: About to create data vector")
    var data Vec<int> = Vec<int>{1, 2, 3}
    println("    DEBUG: Data vector created")
    println("    Created: Vec<int>{1, 2, 3}")
    assert(data.len() == 3, "Initial length should be 3")
    data[1] = 20
    println("    Modified data[1] = 20")
    assert(data[1] == 20, "data[1] should be 20")
    data.push(4)
    data.push(5)
    data.push(6)
    println("    Mixed push syntax")
    println("    Final length:", data.len())
    println("    Elements:", data[0], data[1], data[2], data[3], data[4], data[5])
    println("    DEBUG: About to test length assertion")
    assert(data.len() == 6, "Final length should be 6")
    println("    DEBUG: Length assertion passed")
    println("    DEBUG: About to test data[0] assertion")
    assert(data[0] == 1, "data[0] should be 1")
    println("    DEBUG: data[0] assertion passed")
    println("    DEBUG: About to test data[1] assertion")
    assert(data[1] == 20, "data[1] should be 20")
    println("    DEBUG: data[1] assertion passed")
    println("    DEBUG: About to test data[2] assertion")
    assert(data[2] == 3, "data[2] should be 3")
    println("    DEBUG: data[2] assertion passed")
    println("    DEBUG: About to test data[3] assertion")
    assert(data[3] == 4, "data[3] should be 4")
    println("    DEBUG: data[3] assertion passed")
    println("    DEBUG: About to test data[4] assertion")
    assert(data[4] == 5, "data[4] should be 5")
    println("    DEBUG: data[4] assertion passed")
    println("    DEBUG: About to test data[5] assertion")
    assert(data[5] == 6, "data[5] should be 6")
    println("    DEBUG: data[5] assertion passed")
    println("    [PASS] Comprehensive integration assertions")
    println("")

    println("F2. Complex vector operations with syntax extensions")
    var complex Vec<int> = Vec<int>{10, 20; cap: 15}
    println("    Created: Vec<int>{10, 20; cap: 15}")
    assert(complex.len() == 2, "Initial length should be 2")
    assert(complex.cap() == 15, "Initial capacity should be 15")
    complex.push(30)
    complex.push(40)
    complex.push(50)
    println("    After pushes - Length:", complex.len(), "Capacity:", complex.cap())
    assert(complex.len() == 5, "Length should be 5 after pushes")
    assert(complex.cap() == 15, "Capacity should remain 15")
    
    var complexCopy Vec<int> = complex
    assert(complex[0] == 10, "complex[0] should be 10 before modification")
    assert(complexCopy[0] == 10, "complexCopy[0] should be 10 before modification")
    complex[0] = 999
    println("    After modifying original[0] = 999")
    println("    Original[0]:", complex[0])
    println("    Copy[0]:", complexCopy[0], "(unchanged)")
    println("    DEBUG: About to test complex[0] assertion")
    assert(complex[0] == 999, "complex[0] should be 999 after modification")
    println("    DEBUG: complex[0] assertion passed")
    println("    DEBUG: About to test complexCopy[0] assertion")
    assert(complexCopy[0] == 10, "complexCopy[0] should remain 10")
    println("    DEBUG: complexCopy[0] assertion passed")
    println("    [PASS] Complex operations assertions")
    println("")

    println("[PASSED] Advanced integration")
    println("")
}

func test_vector_push_methods() {
    println("[PART G] Push Method Verification")
    println("")
    
    println("G1. Basic push functionality")
    var pushTest Vec<int> = Vec<int>{10, 20, 30}
    println("    Initial: Length:", pushTest.len())
    pushTest.push(40)
    pushTest.push(50)
    println("    After push - Length:", pushTest.len())
    println("    Elements:", pushTest[0], pushTest[1], pushTest[2], pushTest[3], pushTest[4])
    assert(pushTest.len() == 5, "Length should be 5 after push")
    assert(pushTest[3] == 40, "pushTest[3] should be 40")
    assert(pushTest[4] == 50, "pushTest[4] should be 50")
    println("    [PASS] Basic push functionality")
    
    println("G2. Push with pre-allocated capacity")
    var pushCap Vec<int> = Vec<int>{cap: 20}
    println("    Initial capacity:", pushCap.cap())
    pushCap.push(100)
    pushCap.push(200)
    pushCap.push(300)
    println("    After push - Length:", pushCap.len(), "Capacity:", pushCap.cap())
    assert(pushCap.len() == 3, "Length should be 3 after push")
    assert(pushCap.cap() == 20, "Capacity should remain 20")
    assert(pushCap[0] == 100, "pushCap[0] should be 100")
    assert(pushCap[2] == 300, "pushCap[2] should be 300")
    println("    [PASS] Push with pre-allocated capacity")
    
    println("G3. Push independence test")
    var push1 Vec<int> = Vec<int>{1, 2}
    var push2 Vec<int> = push1
    push1.push(3)
    push2.push(4)
    println("    push1 length:", push1.len(), "push2 length:", push2.len())
    assert(push1.len() == 3, "push1 length should be 3")
    assert(push2.len() == 3, "push2 length should be 3")
    assert(push1[2] == 3, "push1[2] should be 3")
    assert(push2[2] == 4, "push2[2] should be 4")
    println("    [PASS] Push independence test")
    
    println("")
    println("[PASSED] Push method verification")
    println("")
}

func test_vector_pop_methods() {
    println("[PART H] Pop Method Verification")
    println("")
    
    println("H1. Basic pop functionality")
    var popTest Vec<int> = Vec<int>{100, 200, 300, 400, 500}
    println("    Initial: Length:", popTest.len())
    println("    Elements:", popTest[0], popTest[1], popTest[2], popTest[3], popTest[4])
    var popped int = popTest.pop()
    println("    Popped element:", popped)
    println("    After pop - Length:", popTest.len())
    println("    Remaining elements:", popTest[0], popTest[1], popTest[2], popTest[3])
    assert(popTest.len() == 4, "Length should be 4 after pop")
    assert(popped == 500, "Popped element should be 500")
    assert(popTest[3] == 400, "popTest[3] should be 400")
    println("    [PASS] Basic pop functionality")
    
    println("H2. Multiple pops")
    popped = popTest.pop()
    println("    Second pop:", popped, "Length:", popTest.len())
    popped = popTest.pop()
    println("    Third pop:", popped, "Length:", popTest.len())
    assert(popTest.len() == 2, "Length should be 2 after multiple pops")
    assert(popped == 300, "Third popped element should be 300")
    println("    [PASS] Multiple pops")
    
    println("H3. Pop from empty vector")
    popped = popTest.pop()
    popped = popTest.pop()
    popped = popTest.pop()  // This should return 0
    println("    Popped from empty vector:", popped)
    println("    Length after pop from empty:", popTest.len())
    assert(popTest.len() == 0, "Length should be 0 after popping all elements")
    assert(popped == 0, "Popped from empty vector should be 0")
    println("    [PASS] Pop from empty vector")
    
    println("H4. Pop with pre-allocated capacity")
    var popCap Vec<int> = Vec<int>{10, 20, 30; cap: 50}
    println("    Initial - Length:", popCap.len(), "Capacity:", popCap.cap())
    popped = popCap.pop()
    println("    After pop - Length:", popCap.len(), "Capacity:", popCap.cap())
    assert(popCap.len() == 2, "Length should be 2 after pop")
    assert(popCap.cap() == 50, "Capacity should remain 50")
    assert(popped == 30, "Popped element should be 30")
    println("    [PASS] Pop with pre-allocated capacity")
    
    println("")
    println("[PASSED] Pop method verification")
    println("")
}

func test_vector_remove_methods() {
    println("[PART I] Remove Method Verification")
    println("")
    
    println("I1. Basic remove functionality")
    var removeTest Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    Initial: Length:", removeTest.len())
    println("    Elements:", removeTest[0], removeTest[1], removeTest[2], removeTest[3], removeTest[4])
    var removed int = removeTest.remove(1)
    println("    Removed element at index 1:", removed)
    println("    After remove - Length:", removeTest.len())
    println("    Remaining elements:", removeTest[0], removeTest[1], removeTest[2], removeTest[3])
    assert(removeTest.len() == 4, "Length should be 4 after remove")
    assert(removed == 20, "Removed element should be 20")
    assert(removeTest[0] == 10, "Element 0 should be 10")
    assert(removeTest[1] == 30, "Element 1 should be 30 (shifted from index 2)")
    assert(removeTest[2] == 40, "Element 2 should be 40 (shifted from index 3)")
    assert(removeTest[3] == 50, "Element 3 should be 50 (shifted from index 4)")
    println("    [PASS] Basic remove functionality")
    
    println("I2. Remove first element")
    removed = removeTest.remove(0)
    println("    Removed first element:", removed)
    println("    After remove - Length:", removeTest.len())
    println("    Remaining elements:", removeTest[0], removeTest[1], removeTest[2])
    assert(removeTest.len() == 3, "Length should be 3 after removing first")
    assert(removed == 10, "Removed first element should be 10")
    assert(removeTest[0] == 30, "Element 0 should be 30 (was at index 1)")
    assert(removeTest[1] == 40, "Element 1 should be 40 (was at index 2)")
    assert(removeTest[2] == 50, "Element 2 should be 50 (was at index 3)")
    println("    [PASS] Remove first element")
    
    println("I3. Remove last element")
    removed = removeTest.remove(2)
    println("    Removed last element:", removed)
    println("    After remove - Length:", removeTest.len())
    println("    Remaining elements:", removeTest[0], removeTest[1])
    assert(removeTest.len() == 2, "Length should be 2 after removing last")
    assert(removed == 50, "Removed last element should be 50")
    assert(removeTest[0] == 30, "Element 0 should be 30")
    assert(removeTest[1] == 40, "Element 1 should be 40")
    println("    [PASS] Remove last element")
    
    println("I4. Remove from single element vector")
    var single Vec<int> = Vec<int>{100}
    var single_removed int = single.remove(0)
    println("    Removed from single element:", single_removed)
    println("    Length after removal:", single.len())
    assert(single_removed == 100, "Removed element should be 100")
    assert(single.len() == 0, "Length should be 0 after removing only element")
    println("    [PASS] Remove from single element vector")
    
    println("I5. Bounds checking")
    var boundsTest Vec<int> = Vec<int>{1, 2, 3}
    var invalid_removed int = boundsTest.remove(5)
    println("    Invalid removal result:", invalid_removed)
    println("    Length after invalid removal:", boundsTest.len())
    assert(invalid_removed == 0, "Invalid removal should return 0")
    assert(boundsTest.len() == 3, "Length should remain 3 after invalid removal")
    
    var negative_removed int = boundsTest.remove(-1)
    println("    Negative index removal result:", negative_removed)
    println("    Length after negative removal:", boundsTest.len())
    assert(negative_removed == 0, "Negative index removal should return 0")
    assert(boundsTest.len() == 3, "Length should remain 3 after negative index removal")
    println("    [PASS] Bounds checking")
    
    println("I6. Multiple consecutive removals")
    var multi Vec<int> = Vec<int>{1, 2, 3, 4, 5, 6}
    println("    Initial:", multi[0], multi[1], multi[2], multi[3], multi[4], multi[5])
    
    var removed1 int = multi.remove(2)
    println("    After removing index 2 (value 3):", multi[0], multi[1], multi[2], multi[3], multi[4])
    assert(removed1 == 3, "First removal should be 3")
    assert(multi.len() == 5, "Length should be 5")
    assert(multi[2] == 4, "Element at index 2 should now be 4")
    
    var removed2 int = multi.remove(1)
    println("    After removing index 1 (value 2):", multi[0], multi[1], multi[2], multi[3])
    assert(removed2 == 2, "Second removal should be 2")
    assert(multi.len() == 4, "Length should be 4")
    assert(multi[1] == 4, "Element at index 1 should now be 4")
    
    var removed3 int = multi.remove(0)
    println("    After removing index 0 (value 1):", multi[0], multi[1], multi[2])
    assert(removed3 == 1, "Third removal should be 1")
    assert(multi.len() == 3, "Length should be 3")
    assert(multi[0] == 4, "Element at index 0 should now be 4")
    println("    [PASS] Multiple consecutive removals")
    
    println("")
    println("[PASSED] Remove method verification")
    println("")
}

func test_vector_insert_methods() {
    println("[PART J] Insert Method Verification")
    println("")
    
    println("J1. Basic insert functionality")
    var insertTest Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    Initial: Length:", insertTest.len())
    println("    Elements:", insertTest[0], insertTest[1], insertTest[2], insertTest[3], insertTest[4])
    var inserted int = insertTest.insert(2, 25)
    println("    Inserted element at index 2:", inserted)
    println("    After insert - Length:", insertTest.len())
    println("    New elements:", insertTest[0], insertTest[1], insertTest[2], insertTest[3], insertTest[4], insertTest[5])
    assert(insertTest.len() == 6, "Length should be 6 after insert")
    assert(inserted == 25, "Inserted element should be 25")
    assert(insertTest[2] == 25, "Element at index 2 should be the inserted value 25")
    println("    [PASS] Basic insert functionality")
    
    println("J2. Insert at beginning")
    var insertBegin Vec<int> = Vec<int>{100, 200, 300}
    inserted = insertBegin.insert(0, 50)
    println("    Inserted at beginning:", inserted)
    println("    After insert - Length:", insertBegin.len())
    println("    New elements:", insertBegin[0], insertBegin[1], insertBegin[2], insertBegin[3])
    assert(insertBegin.len() == 4, "Length should be 4 after insert at beginning")
    assert(inserted == 50, "Inserted element should be 50")
    assert(insertBegin[0] == 50, "Element at index 0 should be the inserted value 50")
    println("    [PASS] Insert at beginning")
    
    println("J3. Insert at end")
    var insertEnd Vec<int> = Vec<int>{1, 2, 3}
    inserted = insertEnd.insert(3, 4)
    println("    Inserted at end:", inserted)
    println("    After insert - Length:", insertEnd.len())
    println("    New elements:", insertEnd[0], insertEnd[1], insertEnd[2], insertEnd[3])
    assert(insertEnd.len() == 4, "Length should be 4 after insert at end")
    assert(inserted == 4, "Inserted element should be 4")
    assert(insertEnd[3] == 4, "Element at index 3 should be the inserted value 4")
    println("    [PASS] Insert at end")
    
    println("J4. Insert into empty vector")
    var emptyInsert Vec<int> = Vec<int>{}
    inserted = emptyInsert.insert(0, 42)
    println("    Inserted into empty vector:", inserted)
    println("    After insert - Length:", emptyInsert.len())
    println("    New elements:", emptyInsert[0])
    assert(emptyInsert.len() == 1, "Length should be 1 after insert into empty vector")
    assert(inserted == 42, "Inserted element should be 42")
    assert(emptyInsert[0] == 42, "Element at index 0 should be the inserted value 42")
    println("    [PASS] Insert into empty vector")
    
    println("J5. Bounds checking")
    var boundsInsert Vec<int> = Vec<int>{1, 2, 3}
    var invalid_inserted int = boundsInsert.insert(5, 99)
    println("    Invalid insertion result:", invalid_inserted)
    println("    Length after invalid insertion:", boundsInsert.len())
    assert(invalid_inserted == 0, "Invalid insertion should return 0")
    assert(boundsInsert.len() == 3, "Length should remain 3 after invalid insertion")
    
    var negative_inserted int = boundsInsert.insert(-1, 99)
    println("    Negative index insertion result:", negative_inserted)
    println("    Length after negative insertion:", boundsInsert.len())
    assert(negative_inserted == 0, "Negative index insertion should return 0")
    assert(boundsInsert.len() == 3, "Length should remain 3 after negative index insertion")
    println("    [PASS] Bounds checking")
    
    println("")
    println("[PASSED] Insert method verification")
    println("")
}

func test_vector_reserve_methods() {
    println("[PART K] Reserve Method Verification")
    println("")

    println("K1. Basic reserve - increase capacity")
    var reserveTest Vec<int> = Vec<int>{10, 20, 30}
    println("    Initial: Length:", reserveTest.len(), "Capacity:", reserveTest.cap())
    assert(reserveTest.len() == 3, "Initial length should be 3")
    assert(reserveTest.cap() == 3, "Initial capacity should be 3")
    assert(reserveTest[0] == 10, "reserveTest[0] should be 10")
    assert(reserveTest[1] == 20, "reserveTest[1] should be 20")
    assert(reserveTest[2] == 30, "reserveTest[2] should be 30")

    reserveTest.reserve(10)
    println("    After reserve(10): Length:", reserveTest.len(), "Capacity:", reserveTest.cap())
    assert(reserveTest.len() == 3, "Length should remain 3 after reserve")
    assert(reserveTest.cap() == 10, "Capacity should be 10 after reserve")
    assert(reserveTest[0] == 10, "reserveTest[0] should still be 10")
    assert(reserveTest[1] == 20, "reserveTest[1] should still be 20")
    assert(reserveTest[2] == 30, "reserveTest[2] should still be 30")
    println("    [PASS] Basic reserve - increase capacity")

    println("K2. Reserve with smaller capacity (no realloc)")
    var oldCap int64 = reserveTest.cap()
    reserveTest.reserve(5)
    println("    After reserve(5): Length:", reserveTest.len(), "Capacity:", reserveTest.cap())
    assert(reserveTest.len() == 3, "Length should remain 3")
    assert(reserveTest.cap() == oldCap, "Capacity should remain unchanged when requesting smaller capacity")
    assert(reserveTest[0] == 10, "Data should be preserved")
    assert(reserveTest[1] == 20, "Data should be preserved")
    assert(reserveTest[2] == 30, "Data should be preserved")
    println("    [PASS] Reserve with smaller capacity")

    println("K3. Push after reserve (uses reserved capacity)")
    var beforePushCap int64 = reserveTest.cap()
    reserveTest.push(40)
    reserveTest.push(50)
    println("    After pushing 2 elements: Length:", reserveTest.len(), "Capacity:", reserveTest.cap())
    assert(reserveTest.len() == 5, "Length should be 5 after pushes")
    assert(reserveTest.cap() == beforePushCap, "Capacity should not change (using reserved space)")
    assert(reserveTest[3] == 40, "reserveTest[3] should be 40")
    assert(reserveTest[4] == 50, "reserveTest[4] should be 50")
    println("    [PASS] Push after reserve")

    println("K4. Reserve from empty vector")
    var emptyReserve Vec<int> = Vec<int>{}
    println("    Before reserve: Length:", emptyReserve.len(), "Capacity:", emptyReserve.cap())
    assert(emptyReserve.len() == 0, "Empty vector should have length 0")
    assert(emptyReserve.cap() == 0, "Empty vector should have capacity 0")

    emptyReserve.reserve(20)
    println("    After reserve(20): Length:", emptyReserve.len(), "Capacity:", emptyReserve.cap())
    assert(emptyReserve.len() == 0, "Length should remain 0 after reserve")
    assert(emptyReserve.cap() == 20, "Capacity should be 20 after reserve")

    emptyReserve.push(100)
    emptyReserve.push(200)
    println("    After pushing 2 elements: Length:", emptyReserve.len(), "Capacity:", emptyReserve.cap())
    assert(emptyReserve.len() == 2, "Length should be 2 after pushes")
    assert(emptyReserve.cap() == 20, "Capacity should remain 20")
    assert(emptyReserve[0] == 100, "emptyReserve[0] should be 100")
    assert(emptyReserve[1] == 200, "emptyReserve[1] should be 200")
    println("    [PASS] Reserve from empty vector")

    println("K5. Reserve with pre-allocated vector")
    var preallocated Vec<int> = Vec<int>{1, 2, 3; cap: 5}
    println("    Initial: Length:", preallocated.len(), "Capacity:", preallocated.cap())
    assert(preallocated.len() == 3, "Initial length should be 3")
    assert(preallocated.cap() == 5, "Initial capacity should be 5")

    preallocated.reserve(5)
    println("    After reserve(5): Length:", preallocated.len(), "Capacity:", preallocated.cap())
    assert(preallocated.len() == 3, "Length should remain 3")
    assert(preallocated.cap() == 5, "Capacity should remain 5 (no realloc needed)")

    preallocated.reserve(15)
    println("    After reserve(15): Length:", preallocated.len(), "Capacity:", preallocated.cap())
    assert(preallocated.len() == 3, "Length should remain 3")
    assert(preallocated.cap() == 15, "Capacity should be 15 after reserve")
    assert(preallocated[0] == 1, "preallocated[0] should be 1")
    assert(preallocated[1] == 2, "preallocated[1] should be 2")
    assert(preallocated[2] == 3, "preallocated[2] should be 3")
    println("    [PASS] Reserve with pre-allocated vector")

    println("K6. Reserve maintains independence (deep copy)")
    var reserve1 Vec<int> = Vec<int>{10, 20, 30}
    var reserve2 Vec<int> = reserve1
    println("    Created two independent vectors")
    assert(reserve1.len() == 3, "reserve1 should have length 3")
    assert(reserve2.len() == 3, "reserve2 should have length 3")

    reserve1.reserve(20)
    println("    After reserve1.reserve(20):")
    println("    reserve1 - Length:", reserve1.len(), "Capacity:", reserve1.cap())
    println("    reserve2 - Length:", reserve2.len(), "Capacity:", reserve2.cap())
    assert(reserve1.cap() == 20, "reserve1 capacity should be 20")
    assert(reserve2.cap() == 3, "reserve2 capacity should remain 3 (independent)")
    assert(reserve1[0] == 10, "reserve1 data preserved")
    assert(reserve2[0] == 10, "reserve2 data unchanged")
    println("    [PASS] Reserve maintains independence")

    println("")
    println("[PASSED] Reserve method verification")
    println("")
}

func test_vector_contains_methods() {
    println("[PART L] Contains Method Verification")
    println("")

    println("L1. Basic contains - element exists")
    var containsTest Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    Vec: [10, 20, 30, 40, 50]")
    var has20 bool = containsTest.contains(20)
    println("    contains(20):", has20)
    assert(has20 == true, "Should contain 20")

    var has30 bool = containsTest.contains(30)
    println("    contains(30):", has30)
    assert(has30 == true, "Should contain 30")
    println("    [PASS] Basic contains - element exists")

    println("L2. Contains - element does not exist")
    var has99 bool = containsTest.contains(99)
    println("    contains(99):", has99)
    assert(has99 == false, "Should not contain 99")

    var has0 bool = containsTest.contains(0)
    println("    contains(0):", has0)
    assert(has0 == false, "Should not contain 0")
    println("    [PASS] Contains - element does not exist")

    println("L3. Contains - first and last elements")
    var hasFirst bool = containsTest.contains(10)
    println("    contains(10) [first]:", hasFirst)
    assert(hasFirst == true, "Should contain first element 10")

    var hasLast bool = containsTest.contains(50)
    println("    contains(50) [last]:", hasLast)
    assert(hasLast == true, "Should contain last element 50")
    println("    [PASS] Contains - first and last elements")

    println("L4. Contains - empty vector")
    var emptyContains Vec<int> = Vec<int>{}
    var hasInEmpty2 bool = emptyContains.contains(1)
    println("    Empty vector contains(1):", hasInEmpty2)
    assert(hasInEmpty2 == false, "Empty vector should not contain any element")

    var hasInEmpty3 bool = emptyContains.contains(0)
    println("    Empty vector contains(0):", hasInEmpty3)
    assert(hasInEmpty3 == false, "Empty vector should not contain any element")
    println("    [PASS] Contains - empty vector")

    println("L5. Contains - single element vector")
    var singleContains Vec<int> = Vec<int>{42}
    var hasSingle bool = singleContains.contains(42)
    println("    Single element [42] contains(42):", hasSingle)
    assert(hasSingle == true, "Should contain the only element")

    var hasNotSingle bool = singleContains.contains(41)
    println("    Single element [42] contains(41):", hasNotSingle)
    assert(hasNotSingle == false, "Should not contain other elements")
    println("    [PASS] Contains - single element vector")

    println("L6. Contains - duplicate elements")
    var duplicates Vec<int> = Vec<int>{1, 2, 3, 2, 4, 2, 5}
    println("    Vec with duplicates: [1, 2, 3, 2, 4, 2, 5]")
    var hasDup bool = duplicates.contains(2)
    println("    contains(2):", hasDup)
    assert(hasDup == true, "Should find duplicate element")

    var hasDup3 bool = duplicates.contains(3)
    println("    contains(3):", hasDup3)
    assert(hasDup3 == true, "Should find unique element among duplicates")
    println("    [PASS] Contains - duplicate elements")

    println("")
    println("[PASSED] Contains method verification")
    println("")
}

func test_vector_extend_methods() {
    println("[PART M] Extend Method Verification")
    println("")

    println("M1. Basic extend")
    var ext1 Vec<int> = Vec<int>{1, 2, 3}
    var ext2 Vec<int> = Vec<int>{4, 5, 6}
    println("    ext1: [1, 2, 3], ext2: [4, 5, 6]")
    assert(ext1.len() == 3, "ext1 initial length should be 3")
    assert(ext2.len() == 3, "ext2 initial length should be 3")

    ext1.extend(ext2)
    println("    After ext1.extend(ext2):")
    println("    ext1 len:", ext1.len(), "ext2 len:", ext2.len())
    assert(ext1.len() == 6, "ext1 should have 6 elements after extend")
    assert(ext2.len() == 3, "ext2 should still have 3 elements")
    assert(ext1[0] == 1, "ext1[0] should be 1")
    assert(ext1[1] == 2, "ext1[1] should be 2")
    assert(ext1[2] == 3, "ext1[2] should be 3")
    assert(ext1[3] == 4, "ext1[3] should be 4 from ext2")
    assert(ext1[4] == 5, "ext1[4] should be 5 from ext2")
    assert(ext1[5] == 6, "ext1[5] should be 6 from ext2")
    assert(ext2[0] == 4, "ext2[0] should remain 4")
    assert(ext2[1] == 5, "ext2[1] should remain 5")
    assert(ext2[2] == 6, "ext2[2] should remain 6")
    println("    [PASS] Basic extend")

    println("M2. Extend with empty vector")
    var ext3 Vec<int> = Vec<int>{10, 20}
    var ext4 Vec<int> = Vec<int>{}
    println("    ext3: [10, 20], ext4: []")
    assert(ext3.len() == 2, "ext3 initial length")
    assert(ext4.len() == 0, "ext4 should be empty")
    assert(ext4.is_empty(), "ext4 isEmpty should be true")

    ext3.extend(ext4)
    println("    After ext3.extend(ext4): ext3 len:", ext3.len())
    assert(ext3.len() == 2, "ext3 length should remain 2")
    assert(ext4.len() == 0, "ext4 should still be empty")
    assert(ext3[0] == 10, "ext3[0] should be 10")
    assert(ext3[1] == 20, "ext3[1] should be 20")
    println("    [PASS] Extend with empty vector")

    println("M3. Extend empty with non-empty")
    var ext5 Vec<int> = Vec<int>{}
    var ext6 Vec<int> = Vec<int>{100, 200, 300}
    println("    ext5: [], ext6: [100, 200, 300]")
    assert(ext5.len() == 0, "ext5 should be empty")
    assert(ext6.len() == 3, "ext6 length should be 3")

    ext5.extend(ext6)
    println("    After ext5.extend(ext6): ext5 len:", ext5.len())
    assert(ext5.len() == 3, "ext5 should now have 3 elements")
    assert(ext5[0] == 100, "ext5[0] should be 100")
    assert(ext5[1] == 200, "ext5[1] should be 200")
    assert(ext5[2] == 300, "ext5[2] should be 300")
    assert(ext6.len() == 3, "ext6 should remain unchanged")
    println("    [PASS] Extend empty with non-empty")

    println("M4. Multiple extends")
    var ext7 Vec<int> = Vec<int>{1}
    var ext8 Vec<int> = Vec<int>{2, 3}
    var ext9 Vec<int> = Vec<int>{4, 5, 6}
    println("    ext7: [1], ext8: [2, 3], ext9: [4, 5, 6]")

    ext7.extend(ext8)
    println("    After first extend: ext7 len:", ext7.len())
    assert(ext7.len() == 3, "ext7 should have 3 elements after first extend")
    assert(ext7[0] == 1, "ext7[0] should be 1")
    assert(ext7[1] == 2, "ext7[1] should be 2")
    assert(ext7[2] == 3, "ext7[2] should be 3")

    ext7.extend(ext9)
    println("    After second extend: ext7 len:", ext7.len())
    assert(ext7.len() == 6, "ext7 should have 6 elements after second extend")
    assert(ext7[0] == 1, "ext7[0] should be 1")
    assert(ext7[5] == 6, "ext7[5] should be 6")
    println("    [PASS] Multiple extends")

    println("M5. Independence (deep copy semantics)")
    var ext10 Vec<int> = Vec<int>{10, 20}
    var ext11 Vec<int> = Vec<int>{30, 40}
    println("    ext10: [10, 20], ext11: [30, 40]")

    ext10.extend(ext11)
    println("    After extend: ext10 len:", ext10.len())
    assert(ext10.len() == 4, "ext10 should have 4 elements")

    ext10[0] = 999
    ext10[2] = 888
    println("    Modified ext10[0]=999, ext10[2]=888")
    assert(ext10[0] == 999, "ext10[0] should be 999")
    assert(ext10[2] == 888, "ext10[2] should be 888 (was ext11[0])")
    assert(ext11[0] == 30, "ext11[0] should remain 30 (independent)")
    assert(ext11[1] == 40, "ext11[1] should remain 40 (independent)")
    println("    [PASS] Independence")

    println("M6. Pre-allocated capacity (no reallocation)")
    var ext12 Vec<int> = Vec<int>{1, 2; cap: 10}
    var ext13 Vec<int> = Vec<int>{3, 4, 5}
    println("    ext12: [1, 2; cap: 10], ext13: [3, 4, 5]")
    var old_cap12 int64 = ext12.cap()
    assert(ext12.cap() == 10, "ext12 initial capacity should be 10")

    ext12.extend(ext13)
    println("    After extend: ext12 len:", ext12.len(), "cap:", ext12.cap())
    assert(ext12.len() == 5, "ext12 should have 5 elements")
    assert(ext12.cap() == old_cap12, "ext12 capacity should remain unchanged")
    assert(ext12[0] == 1, "ext12[0] should be 1")
    assert(ext12[4] == 5, "ext12[4] should be 5")
    println("    [PASS] Pre-allocated capacity")

    println("M7. Reallocation (capacity growth)")
    var ext14 Vec<int> = Vec<int>{1, 2}
    var ext15 Vec<int> = Vec<int>{3, 4, 5, 6, 7, 8, 9, 10}
    println("    ext14: [1, 2], ext15: [3, 4, 5, 6, 7, 8, 9, 10]")
    var initial_cap14 int64 = ext14.cap()

    ext14.extend(ext15)
    println("    After extend: ext14 len:", ext14.len(), "cap:", ext14.cap())
    assert(ext14.len() == 10, "ext14 should have 10 elements")
    assert(ext14.cap() >= 10, "ext14 capacity should be at least 10")
    assert(ext14.cap() > initial_cap14, "ext14 should have reallocated")
    assert(ext14[0] == 1, "ext14[0] should be 1")
    assert(ext14[9] == 10, "ext14[9] should be 10")
    println("    [PASS] Reallocation")

    println("")
    println("[PASSED] Extend method verification")
    println("")
}

func test_vector_for_in_iteration() {
    println("[PART N] For-In Loop Iteration")
    println("")

    println("N1. Basic for-in iteration")
    var forInTest1 Vec<int> = Vec<int>{10, 20, 30, 40, 50}
    println("    Iterating over [10, 20, 30, 40, 50]:")
    var forInSum1 int = 0
    var forInCount1 int = 0
    for var n int in forInTest1 {
        println("      Element:", n)
        forInSum1 = forInSum1 + n
        forInCount1 = forInCount1 + 1
    }
    assert(forInSum1 == 150, "Sum should be 150")
    assert(forInCount1 == 5, "Should iterate 5 times")
    println("    [PASS] Basic for-in iteration")

    println("N2. For-in with empty vector")
    var forInEmpty Vec<int> = Vec<int>{}
    var emptyCount int = 0
    for var e int in forInEmpty {
        emptyCount = emptyCount + 1
        println("      This should not print:", e)
    }
    assert(emptyCount == 0, "Should not iterate over empty vector")
    println("    [PASS] For-in with empty vector")

    println("N3. For-in with single element")
    var forInSingle Vec<int> = Vec<int>{42}
    var singleValue int = 0
    for var s int in forInSingle {
        singleValue = s
    }
    assert(singleValue == 42, "Should find element 42")
    println("    [PASS] For-in with single element")

    println("N4. For-in value semantics (copy)")
    var forInOriginal Vec<int> = Vec<int>{1, 2, 3}
    println("    Original before loop: [1, 2, 3]")
    for var v int in forInOriginal {
        v = v * 10
        println("      v in loop:", v)
    }
    println("    Original after loop: [", forInOriginal[0], forInOriginal[1], forInOriginal[2], "]")
    assert(forInOriginal[0] == 1, "original[0] should remain 1")
    assert(forInOriginal[1] == 2, "original[1] should remain 2")
    assert(forInOriginal[2] == 3, "original[2] should remain 3")
    println("    [PASS] For-in value semantics")

    println("N5. For-in with bool vector")
    var forInFlags Vec<bool> = Vec<bool>{true, false, true, true, false}
    var trueCount int = 0
    var falseCount int = 0
    for var flag bool in forInFlags {
        if flag {
            trueCount = trueCount + 1
        } else {
            falseCount = falseCount + 1
        }
    }
    assert(trueCount == 3, "Should have 3 true values")
    assert(falseCount == 2, "Should have 2 false values")
    println("    [PASS] For-in with bool vector")

    println("N6. Nested for-in loops")
    var forInOuter Vec<int> = Vec<int>{1, 2, 3}
    var forInInner Vec<int> = Vec<int>{10, 20}
    var pairCount int = 0
    for var i int in forInOuter {
        for var j int in forInInner {
            pairCount = pairCount + 1
            println("      Pair:", i, j)
        }
    }
    assert(pairCount == 6, "Should have 6 pairs (3 * 2)")
    println("    [PASS] Nested for-in loops")

    println("N7. For-in with pre-allocated vector")
    var forInPrealloc Vec<int> = Vec<int>{100, 200, 300; cap: 10}
    var preallocSum int = 0
    for var val int in forInPrealloc {
        preallocSum = preallocSum + val
    }
    assert(preallocSum == 600, "Sum should be 600")
    println("    [PASS] For-in with pre-allocated vector")

    println("N8. For-in with dynamically grown vector")
    var forInDynamic Vec<int> = Vec<int>{1, 2}
    forInDynamic.push(3)
    forInDynamic.push(4)
    forInDynamic.push(5)
    var dynamicSum int = 0
    for var d int in forInDynamic {
        dynamicSum = dynamicSum + d
    }
    assert(dynamicSum == 15, "Sum should be 15")
    println("    [PASS] For-in with dynamically grown vector")

    println("N9. For-in accumulation pattern")
    var forInAccum Vec<int> = Vec<int>{1, 2, 3, 4, 5}
    var product int = 1
    for var num int in forInAccum {
        product = product * num
    }
    assert(product == 120, "Product should be 120 (5!)")
    println("    [PASS] For-in accumulation pattern")

    println("")
    println("[PASSED] For-in loop iteration")
    println("")

    // =====================================================
    // Final Summary
    // =====================================================
    println("=========================================")
    println("ALL TESTS PASSED!")
    println("=========================================")
}
